﻿<UserControl x:Class="RialternativeSample.Client.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
             xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
             xmlns:dataControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:controls="clr-namespace:RialternativeSample.Client.Controls"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:s="clr-namespace:FirstLook.ServiceModel.DomainServices.Client.Security;assembly=FirstLook.ServiceModel.DomainServices.Client.Security"
             mc:Ignorable="d"
             d:DesignWidth="640"
             d:DesignHeight="480"
             DataContext="{Binding MainViewModel, Source={StaticResource ViewModelLocator}}">
    <toolkit:BusyIndicator IsBusy="{Binding IsBusy}"
                           HorizontalAlignment="Stretch">
        <Grid>
            <controls:TiledBackground SourceUri="/RialternativeSample;component/Resources/Images/backgroundtexture.png" />
            <Image Source="/RialternativeSample;component/Resources/Images/backgroundshadow.png"
                   Stretch="Fill" />

            <Border Style="{StaticResource BackgroundBorderStyle}">
            </Border>
            <Border Style="{StaticResource NavLinksBorderStyle}" />

            <Border Style="{StaticResource LoginContainerStyle}">
                <Grid>
                    <StackPanel Visibility="{Binding User.IsAuthenticated, Converter={StaticResource NotBooleanToVisibilityConverter}}"
                                Style="{StaticResource LoginPanelStyle}">
                        <Button Content="Login"
                                Command="{Binding LoginCommand}"
                                Style="{StaticResource LoginRegisterLinkStyle}" />
                    </StackPanel>

                    <StackPanel Visibility="{Binding User.IsAuthenticated, Converter={StaticResource BooleanToVisibilityConverter}}"
                                Style="{StaticResource LoginPanelStyle}">
                        <!-- welcomeText.Text property's binding is setup in code-behind -->
                        <TextBlock Style="{StaticResource WelcomeTextStyle}"
                                   VerticalAlignment="Center"
                                   Margin="0,2,0,2"
                                   Text="{Binding User.Name}" />
                        <TextBlock Text="  |  "
                                   Style="{StaticResource SpacerStyle}" />
                        <Button Content="Logout"
                                Command="{Binding LogoutCommand}"
                                Style="{StaticResource LoginRegisterLinkStyle}"
                                IsEnabled="{Binding Path=Authentication.IsLoggingOut, Converter={StaticResource NotOperatorValueConverter}}" />
                    </StackPanel>
                </Grid>
            </Border>

            <Grid Style="{StaticResource LayoutRootGridStyle}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <StackPanel x:Name="LinksStackPanel"
                            Style="{StaticResource LinksStackPanelStyle}">
                    <HyperlinkButton Style="{StaticResource LinkStyle}"
                                     NavigateUri="/CustomersView"
                                     TargetName="ContentFrame"
                                     Content="Customers" />
                    <Rectangle Style="{StaticResource DividerStyle}" />
                    <HyperlinkButton Style="{StaticResource LinkStyle}"
                                     NavigateUri="/ProductsView"
                                     TargetName="ContentFrame"
                                     Content="Products" />
                    <Rectangle Style="{StaticResource DividerStyle}" />
                    <HyperlinkButton Style="{StaticResource LinkStyle}"
                                     NavigateUri="/EmployeesView"
                                     TargetName="ContentFrame"
                                     Content="Employees" />
                    <Rectangle Style="{StaticResource DividerStyle}" />
                    <HyperlinkButton Style="{StaticResource LinkStyle}"
                                     NavigateUri="/AboutView"
                                     TargetName="ContentFrame"
                                     Content="About" />
                </StackPanel>

                <Border Style="{StaticResource NavBrandingBorderStyle}"
                        Grid.Row="1">
                    <StackPanel Style="{StaticResource NavBrandingStackPanelStyle}">
                        <TextBlock Style="{StaticResource ApplicationNameStyle}"
                                   Text="RialternativeSample" />
                        <ContentControl Style="{StaticResource NavLogoIcon}"
                                        VerticalAlignment="Bottom" />
                    </StackPanel>
                </Border>

                <Border Style="{StaticResource NavContentBorderStyle}"
                        Grid.Row="2">
                    <navigation:Frame x:Name="ContentFrame"
                                      Style="{StaticResource ContentFrameStyle}"
                                      Source="/AboutView"
                                      s:Authorization.NavigationMode="Redirect"
                                      Navigated="ContentFrame_Navigated">
                        <navigation:Frame.UriMapper>
                            <uriMapper:UriMapper>
                                <uriMapper:UriMapping Uri=""
                                                      MappedUri="/Views/AboutView.xaml" />
                                <uriMapper:UriMapping Uri="/{pageName}"
                                                      MappedUri="/Views/{pageName}.xaml" />
                            </uriMapper:UriMapper>
                        </navigation:Frame.UriMapper>
                    </navigation:Frame>
                </Border>
            </Grid>
        </Grid>
    </toolkit:BusyIndicator>
</UserControl>